package jm.mq.boot_mq.web;

import com.alibaba.fastjson.JSON;
import jm.mq.boot_mq.vo.MsgVo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : JinMing Zhou
 * @description:
 * @date : 2023/6/1 10:52
 */
@RestController
@RequestMapping("/i/async")
public class IAsyncController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息到async_queue队列名称，不指定交换机
     * @param userId 用户id
     * @param source 新增积分数量
     * @return vo
     */
    @GetMapping("/toAsync")
    public MsgVo toAsync(Long userId, Integer source){
        MsgVo vo = new MsgVo(userId, source);
        rabbitTemplate.convertAndSend("", "async_queue", JSON.toJSONString(vo));
        return vo;
    }


}
